 <?php  
 //pr($batchData);
echo $this->session->flash(); 
if(!empty($batchData)){
    $this->Paginator->options(array(
        'update' => '#divUpdate',
        'evalScripts' => true,
        'url' => array('controller' => 'Payrolls', 'action' => 'admin_index')
    ));
} ?>
<div class="file" id="List">
    <table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#686550">
        <tr class="heading"  bgcolor="#708089">
            <td width="6%" valign="top" align="left"><?php echo __('S.NO') ?></td>
            <td valign="top"  align="left"><?php echo $this->Paginator->sort('unit_code', __('UNIT_CODE', true)); ?></td>
            <td valign="top"  align="left"><?php echo __('UNIT_NAME'); ?></td>
            <td valign="top"  align ="left"><?php echo $this->Paginator->sort('prepared_by', __('PREPARED_BY', true)); ?></td>
            <td valign="top"  align ="left"><?php echo $this->Paginator->sort('prepared_date', __('PREPARED_DATE', true)); ?></td>
            <td valign="top"  align ="left"><?php echo $this->Paginator->sort('verified_by', __('VERIFIED_BY', true)); ?></td>
            <td valign="top"  align ="left"><?php echo $this->Paginator->sort('verified_date', __('VERIFIED_DATE', true)); ?></td>
            <td valign="top"  align ="left"><?php echo $this->Paginator->sort('approved_by', __('APPROVED_BY', true)); ?></td>
            <td valign="top"  align ="left"><?php echo $this->Paginator->sort('approved_date', __('APPROVED_DATE', true)); ?></td>
            <td valign="top"  align ="left"><?php echo $this->Paginator->sort('endorse_by', __('ENDORSE_BY', true)); ?></td>
            <td valign="top"  align ="left"><?php echo $this->Paginator->sort('endorse_date', __('ENDORSE_DATE', true)); ?></td>
            <td valign="top"  align ="left"><?php echo $this->Paginator->sort('payable_count', __('CNT', true)); ?></td>
            <td valign="top"  align ="left" class="integer"><?php echo $this->Paginator->sort('total_amount', __('TOTAL', true)); ?></td>
            <td valign="top"  align ="left" class="integer"><?php echo $this->Paginator->sort('total_amount', __('ON_HOLD', true)); ?></td>
            <td valign="top"  align="left"><?php echo __('ACTION'); ?></td>
        </tr>
        <?php
        if (isset($batchData) && count($batchData) > 0) {
            $i = 0;
            foreach ($batchData as $arrayDetail) {
                ?>
                <tr class="heading2" bgcolor="#ffffff">
                    <td>&nbsp;<?php echo $i + 1 ?></td>
                    <td>&nbsp;<?php echo $arrayDetail['BatchList']['unit_code']; ?></td>
                    <td>&nbsp;<?php echo $arrayDetail['ServiceUnit']['unit_name']; ?></td>
                    <td>&nbsp;<?php echo $usersData[$arrayDetail['BatchList']['prepared_by']]; ?></td>
                    <td>&nbsp;<?php echo ($arrayDetail['BatchList']['prepared_date'] != '0000-00-00') ? date('M j, Y', strtotime($arrayDetail['BatchList']['prepared_date'])) : ''; ?></td>
                    <td>&nbsp;<?php echo ($arrayDetail['BatchList']['verified_by']) ? $usersData[$arrayDetail['BatchList']['verified_by']] : ''; ?></td>
                    <td>&nbsp;<?php echo ($arrayDetail['BatchList']['verified_date'] != '0000-00-00') ? date('M j, Y', strtotime($arrayDetail['BatchList']['verified_date'])) : ''; ?></td>
                    <td>&nbsp;<?php echo ($arrayDetail['BatchList']['approved_by']) ? $usersData[$arrayDetail['BatchList']['approved_by']] : ''; ?></td>
                    <td>&nbsp;<?php echo ($arrayDetail['BatchList']['approved_date'] != '0000-00-00') ? date('M j, Y', strtotime($arrayDetail['BatchList']['approved_date'])) : ''; ?></td>
                    <td>&nbsp;<?php echo ($arrayDetail['BatchList']['endorse_by']) ? $usersData[$arrayDetail['BatchList']['endorse_by']] : ''; ?></td>
                    <td>&nbsp;<?php echo ($arrayDetail['BatchList']['endorse_date'] != '0000-00-00') ? date('M j, Y', strtotime($arrayDetail['BatchList']['endorse_date'])) : ''; ?></td>
                    <td>&nbsp;<?php echo isset($payableCount[$arrayDetail['BatchList']['id']]) ? $payableCount[$arrayDetail['BatchList']['id']]: '';  ?></td>
                    <td>&nbsp;<?php echo isset($payableTotal[$arrayDetail['BatchList']['id']]) ? number_format($payableTotal[$arrayDetail['BatchList']['id']], 2) : ''; ?></td>
                    <td>&nbsp;<?php echo isset($payableOnHoldCount[$arrayDetail['BatchList']['id']]) ? $payableOnHoldCount[$arrayDetail['BatchList']['id']] : 0; ?></td>
                    <td>
                        <?php
			$showSeparator = 0;
                        if(!$roleId || $showBatchPaymentRequestURLAdmin){//No checks for superadmin
                            echo $this->html->link($this->Html->image('icons/16/icon_view.gif'), array(
                                'controller' => 'payrolls',
                                'action' => 'admin_view',
                                $arrayDetail['BatchList']['id']), array(
                                'alt' => __('EDIT', true),
                                'title' => __('EDIT', true),
                                'escape'=>false)
                            );
			    $showSeparator = 1;
			}
			if(!$roleId || $showBatchDeleteURLAdmin){//No checks for superadmin
			    if($showSeparator){
				 echo ' | ';
			      }
                            echo $this->Js->link(
                                $this->Html->image('icons/16/cross.png'), 
                                array(
                                    'controller' => 'payrolls',
                                    'action' => 'admin_delete_batch',$arrayDetail['BatchList']['id'], $filterMonth, $filterYear
                                ), 
                                array(
                                    'update' => '#divUpdate',
                                    'alt' => __('DELETE', true),
                                    'title' => __('DELETE', true),
                                    'escape'=>false,
                                    'before' => $this->Js->get('#divUpdate')->effect('fadeOut'),
                                    'success' => $this->Js->get('#divUpdate')->effect('fadeIn'),
                                    'confirm' => 'Are you sure you wish to delete this Batch? You can\'t revert it back'
                                )
                            );
			}
                        ?>
                    </td>
                </tr>  
                <?php
                $i++;
            }
        }
        ?>
        <tr>
            <td colspan="15" bgcolor="#ffffff" align="center">
                <div class="pagination">            
                    <?php
                    if (!empty($batchData)) {
                        echo $this->Element('pagination');
                    } else {
                        echo __("NO_RECORD_MESSAGE");
                    }
                    ?>              
                </div>
            </td>
        </tr>

        <tr bgcolor="#ffffff">
            <td colspan="15" valign="top">
                <table width="30%">
                    <tr>
                        <td width="10%">
                            <b><?php echo __('LEGENDS') ?> :- </b> 
                        </td>
                        <td width="20%">
                            <?php echo $this->html->image('/img/icons/16/icon_view.gif'); ?>
                            <?php echo __('VIEW') ?>
                        </td>
                        <td width="20%">
                            <?php echo $this->html->image('/img/icons/16/cross.png'); ?>
                            <?php echo __('DELETE') ?>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div><?php
    if (!empty($batchData)) { ?>
        <div style="margin: 10px 0 10px 0;">
                <div style="float: left;">
                    <?php echo $this->Form->create("Payroll", array('action' => 'download')); ?>
                    <div style="float: right; margin-left: 20px; margin-right: 6px;"><?php 
                        echo $this->Form->hidden('Payroll.month', array('value' => $filterMonth, 'type' => 'textfield'));
                        echo $this->Form->hidden('Payroll.year', array('value' => $filterYear, 'type' => 'textfield'));

                        if(!$roleId){//No checks for superadmin
                            echo $this->Form->submit(__('PRINT_TO_PDF', true), array(
                                "class" => "button", 
                                'label' => false, 
                                'div' => false,
                                'name' => 'print_pdf'
                            ));
                            echo '<div class="buttonEnding"></div>';
                        }else{
                            if($showBatchDownloadPDFURLAdmin){
                                echo $this->Form->submit(__('PRINT_TO_PDF', true), array(
                                        "class" => "button", 
                                        'label' => false, 
                                        'div' => false,
                                        'name' => 'print_pdf'
                                    ));
                                echo '<div class="buttonEnding"></div>';
                            }
                        }

                        ?>
                    </div>
                    <div style="float: right;"><?php             
                        if(!$roleId){//No checks for superadmin
                                echo $this->Form->submit(__('PRINT_TO_EXCEL', true), array(
                                    "class" => "button", 
                                    'label' => false, 
                                    'div' => false,
                                    'name' => 'print_excel'
                                ));
                                echo '<div class="buttonEnding"></div>';
                            }else{
                                if($showBatchDownloadExcelURLAdmin){
                                    echo $this->Form->submit(__('PRINT_TO_EXCEL', true), array(
                                            "class" => "button", 
                                            'label' => false, 
                                            'div' => false,
                                            'name' => 'print_excel'
                                        ));
                                    echo '<div class="buttonEnding"></div>';
                                }
                            }?>
                    </div>
                    <?php echo $this->Form->end(); ?>
                    <div style="clear: right;"></div>
                </div>
                <div style="clear: left;"></div>
            </div><?php
    }?>
<?php echo $this->Js->writeBuffer();?>